package com.longteng.diamond.thread;


import com.longteng.diamond.constant.BuildTestStatus;
import com.longteng.diamond.domain.BuildTest;
import com.longteng.diamond.domain.RunTestContext;
import com.longteng.diamond.domain.TestPlan;
import com.longteng.diamond.service.MailReportService;
import com.longteng.diamond.service.RunTestService;
import com.longteng.diamond.service.TestPlanService;
import com.longteng.diamond.util.ReportLogFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.weaver.ast.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: jiaou
 * Date: 15-1-20
 * Time: 下午3:15
 * To change this template use File | Settings | File Templates.
 */
@Slf4j
public class ThreadRunTest implements Runnable {
    private Integer buildTestId;
    private RunTestService runTestService;
    private MailReportService mailReportService;

    public ThreadRunTest(Integer buildTestId, RunTestService runTestService, MailReportService mailReportService) {
        this.buildTestId = buildTestId;
        this.runTestService = runTestService;
        this.mailReportService = mailReportService;
    }

    @Override
    public void run() {
        log.info("开始运行接口!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        RunTestContext runTestContext = new RunTestContext();
        try {
            runTestContext.setBuildTestId(buildTestId);
            runTestService.runTestByBuildTest(runTestContext);
            /**
             * 执行完测试去发送邮件
             * **/
            BuildTest buildTest=runTestContext.getBuildTest();
            mailReportService.sendMail(buildTest);
        } catch (Exception e) {
            log.error("运行测试错误!", e);
        } finally {
            runTestContext.getReportLogFileUtil().closeWriter();
        }
    }

}
